clear

use 
***file path for V-Dem-CY-Full+Others-v14.dta ***

*** Preparing Data

*** Set Panel Data

xtset country_id year, yearly

*** Cleaning name variables

gen histnamecopy = histname

gen s = ustrregexra(histnamecopy,"\[.+?\]","")

split s, parse(,) gen(stub_)

drop histnamecopy stub_2  stub_3  stub_4  stub_5  stub_6  stub_7

rename s onlyhistname

rename stub_1 onlyhistnamecopy



***Creating the descriptor variables

*** Monarchies

gen emirate = 0
replace emirate = 1 if strpos(onlyhistname,"Emirate") >= 1

gen kingdom = 0
replace kingdom = 1 if strpos(onlyhistname,"Kingdom") >= 1

gen empire = 0
replace empire = 1 if strpos(onlyhistname,"Empire") >= 1

gen hereditary = 0
replace hereditary = 1 if strpos(onlyhistname,"hereditary") >= 1

gen beylik = 0
replace beylik = 1 if strpos(onlyhistname,"Beylik") >= 1

gen khaan = 0
replace khaan = 1 if strpos(onlyhistname,"Khaan") >= 1

gen daivietquoc = 0
replace daivietquoc = 1 if strpos(onlyhistname,"Dai Viet Quoc") >= 1

gen duchy = 0
replace duchy = 1 if strpos(onlyhistname,"Duchy") >= 1

gen duchies = 0
replace duchies = 1 if strpos(onlyhistname,"Duchies") >= 1

gen electorate = 0
replace electorate = 1 if strpos(onlyhistname,"Electorate") >= 1

gen landgraviate = 0
replace landgraviate = 1 if strpos(onlyhistname,"Landgraviate") >= 1

gen principality = 0
replace principality = 1 if strpos(onlyhistname,"Principality") >= 1

gen principalities = 0
replace principalities = 1 if strpos(onlyhistname,"Principalities") >= 1

gen Monarchical = 0
replace Monarchical = 1 if emirate == 1 | kingdom == 1 | empire == 1 | hereditary == 1 | beylik == 1 | beylik == 1 | khaan == 1 | daivietquoc == 1 | duchy == 1 | duchies == 1 | electorate == 1 | landgraviate == 1 | principality == 1 | principalities == 1


*** Republic

gen republic = 0
replace republic = 1 if strpos(onlyhistname,"Republic") >= 1

gen commonwealth = 0
replace commonwealth = 1 if strpos(onlyhistname,"Commonwealth") >= 1

gen Republican = 0
replace Republican = 1 if republic == 1 | commonwealth == 1

*** Religion

gen islamic = 0
replace islamic  = 1 if strpos(onlyhistname,"Islamic") >= 1

gen papal = 0
replace papal = 1 if strpos(onlyhistname,"Papal") >= 1

gen bishopric = 0
replace bishopric = 1 if strpos(onlyhistname,"Bishopric") >= 1

gen Religious = 0
replace Religious = 1 if islamic == 1 | papal == 1 | bishopric == 1 

*** Democratic

gen Democratic = 0
replace Democratic = 1 if strpos(onlyhistname,"Democratic") >= 1

*** Socialist 

gen socialist = 0
replace socialist = 1 if strpos(onlyhistname,"Socialist") >= 1

gen soviet = 0
replace soviet = 1 if strpos(onlyhistname,"Soviet") >= 1

gen sovietsocialist = 0
replace sovietsocialist = 1 if soviet == 1 | socialist == 1

gen people = 0
replace people = 1 if strpos(onlyhistname,"People") >= 1

gen jamahiriya = 0
replace jamahiriya = 1 if strpos(onlyhistname,"Jamahiriya") >= 1

gen allpeople = 0
replace allpeople = 1 if jamahiriya == 1 | people == 1

gen Socialist = 0

replace Socialist = 1 if sovietsocialist == 1 | allpeople == 1

 
 ***Creating Controls
 
 gen population = .
 
 replace population = e_mipopula if  e_mipopula != .
 
 replace population = (e_wb_pop/1000) if e_wb_pop != .

 gen lnpopulation = ln(population)
 
 gen lnGDPpercap = ln(e_gdppc)
 
egen lnGDPpercap_avg = mean(lnGDPpercap), by(country_id)

egen lnpopulation_avg = mean(lnpopulation), by(country_id)


label variable lnpopulation_avg "Averaged Log of Population"
label variable lnGDPpercap_avg "Averaged Log of GDP per Capita"

 **** Running Models 

 ***Monarchy
 
 gen Monarchicalsuccession = 0 
 replace Monarchicalsuccession = 1 if v2expathhs == 3 
 replace Monarchicalsuccession = 1 if v2expathhs == 4
 replace Monarchicalsuccession = . if v2expathhs == .

 
gen HoSlifetimetenure = 0 
replace HoSlifetimetenure = 1 if v2exfxtmhs == 100
replace HoSlifetimetenure = . if v2exfxtmhs == .
 
 
 xtlogit  Monarchicalsuccession Monarchical lnpopulation_avg lnGDPpercap_avg,  re
 estimates store A
outreg2 using Table4.doc, replace ctitle(Monarchical Succession) label
 
 xtlogit  Monarchicalsuccession Monarchical lnpopulation_avg lnGDPpercap_avg if year > 1945, re
 
  ttest  Monarchicalsuccession if year == 1855, by(Monarchical) 
 
 xtlogit  HoSlifetimetenure Monarchical lnpopulation_avg lnGDPpercap_avg, re
  estimates store B
outreg2 using Table4.doc, append ctitle(Head of State Lifetime Tenure) label

  
 xtlogit  HoSlifetimetenure Monarchical lnpopulation_avg lnGDPpercap_avg if year > 1945, re
 
  xtlogit  Monarchicalsuccession Monarchical lnpopulation_avg lnGDPpercap_avg if year > 1945, re

   ttest  HoSlifetimetenure if year == 1900, by(Monarchical) 

   
*** Republican

gen Republicansuccession = 0 
 replace Republicansuccession = 1 if v2expathhs == 6 
 replace Republicansuccession = 1 if v2expathhs == 7
   replace Republicansuccession = . if v2expathhs == .


gen HoStermlimits = 0 
replace HoStermlimits = 1 if v2exfxtmhs < 99
replace HoStermlimits = 0 if v2exfxtmhs == 0
replace HoStermlimits = . if v2exfxtmhs == .

xtlogit  Republicansuccession Republican lnpopulation_avg lnGDPpercap_avg,  re
 estimates store C
 outreg2 using Table4.doc, append ctitle(Republican Succession) label
 
 xtlogit  Republicansuccession Republican lnpopulation_avg lnGDPpercap_avg if year > 1945, re
    ttest  Republicansuccession if year == 2016, by(Republican) 


 xtlogit  HoStermlimits Republican lnpopulation_avg lnGDPpercap_avg, re
  estimates store D
   outreg2 using Table4.doc, append ctitle(Head of State Term Limits) label

  
 xtlogit  HoStermlimits Republican lnpopulation_avg lnGDPpercap_avg if year > 1945, re
     ttest  HoStermlimits if year == 2016, by(Republican) 
	 
	 
 xtreg  v2x_polyarchy Republican lnpopulation_avg lnGDPpercap_avg, robust re
   estimates store J
      outreg2 using Table4.doc, append ctitle(Republican Democracy) label

 
  xtreg  v2x_polyarchy Republican lnpopulation_avg lnGDPpercap_avg if year > 1945, robust re
	     ttest  v2x_polyarchy if year == 2016, by(Republican) 

	

***Religious
 
 gen Religiousfreedom = v2clrelig / 4
 
 xtreg  Religiousfreedom Religious lnpopulation_avg lnGDPpercap_avg, robust re
  estimates store F
        outreg2 using Table5.doc, replace ctitle(Religious Freedom) label

  
          ttest  Religiousfreedom if year == 1996, by(Religious) 
        ttest  Religiousfreedom if year == 2011, by(Religious) 


 xtreg v2exl_legitideolcr_4 Religious lnpopulation_avg lnGDPpercap_avg, robust re
   estimates store G
           outreg2 using Table5.doc, append ctitle(Religious Legitimation) label


       ttest  v2exl_legitideolcr_4 if year == 1996, by(Religious) 
        ttest  v2exl_legitideolcr_4 if year == 2011, by(Religious) 
 
   ***Socialist
	  
	  gen Stateownership = -(v2clstown_osp / 4)
	  
	  xtreg v2xeg_eqdr Socialist  lnpopulation_avg lnGDPpercap_avg , robust re
   estimates store H
              outreg2 using Table5.doc, append ctitle(Socialist Equal Resources) label

   
        ttest  v2xeg_eqdr if year == 1983, by(Socialist) 
        ttest  v2xeg_eqdr if year == 1990, by(Socialist) 

   
	  xtreg Stateownership Socialist  lnpopulation_avg lnGDPpercap_avg, robust re
   estimates store I
                 outreg2 using Table5.doc, append ctitle(Socialist State Ownership) label

        ttest  Stateownership if year == 1983, by(Socialist) 
        ttest  Stateownership if year == 1990, by(Socialist) 

	  
	  
	  ttest v2xeg_eqdr if year == 1990, by(Socialist)
	  ttest v2xeg_eqdr if year == 1983, by(Socialist)
  ttest Stateownership if year == 1990, by(Socialist)
	  ttest Stateownership if year == 1983, by(Socialist)

	  
 
 ***Democratic
 
 xtreg  v2x_polyarchy Democratic lnpopulation_avg lnGDPpercap_avg, robust re
  estimates store E
  outreg2 using Table5.doc, append ctitle(Democratic Democracy) label

  
     ttest  v2x_polyarchy if year == 1990, by(Democratic) 
     ttest  v2x_polyarchy if year == 1978, by(Democratic) 
	 
  xtreg v2xeg_eqdr Democratic  lnpopulation_avg lnGDPpercap_avg , robust re
   estimates store K
     outreg2 using Table5.doc, append ctitle(Democratic Equal Resources) label

   
xtreg Stateownership Democratic  lnpopulation_avg lnGDPpercap_avg, robust re
   estimates store L
     outreg2 using Table5.doc, append ctitle(Democratic State Ownership) label

	 

coefplot ///
(A, label(Monarchical Succession) msymbol(d) msize(medlarge) pstyle(p1) offset(0.15) drop(_cons lnpopulation_avg lnGDPpercap_avg)) ///
(B, label(Head of State Life Tenure) msymbol(Dh) msize(medlarge) pstyle(p2) offset(-0.15) drop(_cons lnpopulation_avg lnGDPpercap_avg)) ///
(C, label(Republican Succession) msymbol(o) msize(medlarge) pstyle(p3) offset(0.15) drop(_cons lnpopulation_avg lnGDPpercap_avg)) ///
(D, label(Head of State Limited Term) msymbol(Oh) msize(medlarge) pstyle(p4) offset(-0.15) drop(_cons lnpopulation_avg lnGDPpercap_avg)), ///
plotregion(fcolor(white)) graphregion(fcolor(white)) bgcolor(fcolor(white)) ///
xline(0) xscale(range(0 10)) ///
xtitle("Coefficients with 95% Confidence Intervals", size(medium) margin(medsmall))


coefplot  ///
(J, label(Polyarchy) msymbol(O) pstyle(p5) msize(medlarge) offset(0) drop(_cons lnpopulation_avg lnGDPpercap_avg))  ///
(F, label(Religious Freedom) msymbol(T) pstyle(p6) msize(medlarge) offset(0.15) drop(_cons lnpopulation_avg lnGDPpercap_avg)) ///
(G, label(Religious Legitimation) msymbol(Th) pstyle(p7) msize(medlarge) offset(-0.15) drop(_cons lnpopulation_avg lnGDPpercap_avg)) ///
(H, label(Equal Resources) msymbol(S) pstyle(p8) msize(medlarge) offset(0.15) drop(_cons lnpopulation_avg lnGDPpercap_avg)) ///
(I, label(State Ownership) msymbol(Sh) pstyle(p9) msize(medlarge) offset(-0.15) drop(_cons lnpopulation_avg lnGDPpercap_avg)) ///
(E, label("") msymbol(O) nokey pstyle(p5) msize(medlarge) offset(0.25) drop(_cons lnpopulation_avg lnGDPpercap_avg)) ///
(K, label("") msymbol(S) nokey pstyle(p8) msize(medlarge) offset(0.0) drop(_cons lnpopulation_avg lnGDPpercap_avg)) ///
(L, label("") msymbol(Sh) nokey pstyle(p9) msize(medlarge) offset(-0.25) drop(_cons lnpopulation_avg lnGDPpercap_avg)), ///
plotregion(fcolor(white)) drop(_cons lnpopulation_avg lnGDPpercap_avg) ///
xline(0) xtitle("Coefficients with 95% Confidence Intervals", size(medium) margin(medsmall))
  


